function format(value) {
  var value = value && value.substring(0, 10).replace(/-/gi, "/");
  return value ? new Date(value).Format("yyyy-MM-dd") : "--";
}
export function generateColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    // {
    //   title: this.$t("common.num"),
    //   width: 50,
    //    align: "left",
    //   fixed: "left",
    //   render: (h, params) => {
    //     return h("span", {}, this.getIndex(params.index));
    //   }
    // },
    {
      title: this.$t("module.tenantManage.tenantCode"), // 租户编码
      key: "tenantCode",
      sortable: "custom"
    },
    {
      title: this.$t("module.tenantManage.tenantName"), // 租户名称
      key: "tenantName",
      sortable: "custom"
    },
    // {
    //   title: this.$t("module.tenantManage.defaultUserRepository"), // 默认用户中心
    //   key: "defaultUserRepository",
    //   render: (h, params) => {
    //     return h("span", {}, this.getUserCenterName(params.row.defaultUserRepository));
    //   }
    // },
    {
      title: this.$t("module.tenantManage.tenantType"), // 租户类型
      key: "tenantType",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_3_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_3_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
      render: (h, params) => {
        return h(
          "span",
          {},
          params.row.tenantType == 1
            ? this.$t("module.tenantManage.tenantTypeItem.groupCompany")
            : this.$t("module.tenantManage.tenantTypeItem.company")
        );
      }
    },
    // {
    //   title: this.$t("module.tenantManage.usefulLife"), // 有效期
    //   key: "usefulLife",
    //   width: 180,
    //   render: (h, params) => {
    //     return h(
    //       "span",
    //       {},
    //       params.row.openTime ? format(params.row.openTime) + " - " + format(params.row.expireTime) : ""
    //     );
    //   }
    // },
    {
      title: this.$t("module.tenantManage.startTime"), // 开通日期
      key: "openTime",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
      render: (h, params) => {
        return h("span", {}, params.row.openTime ? format(params.row.openTime) : "");
      }
    },
    {
      title: this.$t("module.tenantManage.endTime"), // 到期日期
      key: "expireTime",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_YYYYMMDD + COLUMN_WIDTH.MAX_WIDTH_MORE,
      align: "center",
      render: (h, params) => {
        return h("span", {}, params.row.expireTime ? format(params.row.expireTime) : "");
      }
    },
    {
      title: this.$t("common.status"),
      align: "center",
      key: "enabled",
      minWidth: 80,
      maxWidth: 80 + COLUMN_WIDTH.MAX_WIDTH_MORE,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            // 修改StatusButton内容居中
            style: {
              "justify-content": "center"
            },
            props: {
              status: params.row.enabled == 1 ? "0" : "1"
            }
          },
          params.row.enabled ? this.$t("common.valid") : this.$t("common.invalid")
        );
      }
    },
    {
      title: this.$t("common.operating"),
      align: "left",
      fixed: "right",
      width: 115,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-create",
                text: this.$t("common.edit"),
                handle: () => {
                  this.edit(params.row);
                }
              },
              {
                type: "icon",
                icon: "ios-person-add",
                text: this.$t("module.tenantManage.administrator"),
                hidden: params.row.tenantCode == window.RPConfig.rootTenantCode,
                handle: () => {
                  this.assginTenantAdmin(params.row);
                }
              },
              {
                type: "icon",
                icon: "ios-build",
                text: this.$t("module.tenantManage.authorization.dev"),
                // hidden: !(this.showdeveloper && params.row.syncLowcode && params.row.tenantCode !== 'Ripples'),
                handle: () => {
                  this.goRole(params.row);
                }
              },
              {
                type: "icon",
                icon: "ios-settings",
                text: this.$t("module.tenantManage.tenantConfig"),
                hidden: params.row.tenantCode == window.RPConfig.rootTenantCode,
                handle: () => {
                  this.configTenant(params.row);
                }
              }
            ]
          }
        });
      }
    }
  ];
}
export function userColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      minWidth: 100
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      minWidth: 90
    },
    {
      title: this.$t("common.status"),
      align: "left",
      key: "locked",
      width: 100,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            props: {
              status: params.row.locked == "0" ? "0" : "1"
            }
          },
          params.row.locked == "0" ? this.$t("common.valid") : this.$t("common.invalid")
        );
      }
    },
    {
      title: this.$t("common.operating"), // 操作按钮
      align: "left",
      width: 60,
      render: (h, params) => {
        return h("RowTools", {
          props: {
            data: [
              {
                type: "icon",
                icon: "md-unlock",
                text: this.$t("module.userManage.unlockUser"),
                hidden: !params.row.loginLocked,
                permission: "USER_INDEX",
                handle: () => {
                  this.unlock(params.row);
                }
              },
              {
                type: "icon",
                icon: "ios-settings",
                text: this.$t("module.tenantManage.authorization.title"),
                hidden: this.administrator == 'administrator',
                handle: () => {
                  this.goLicence(params);
                }
              }
            ]
          }
        });
      }
    }
  ];
}
export function tenantColumns() {
  return [
    {
      type: "selection",
      width: 45,
      align: "center"
    },
    {
      title: this.$t("module.userManage.userAccount"), // 用户账号
      key: "userId",
      minWidth: 100
    },
    {
      title: this.$t("module.userManage.name"), // 用户名称
      key: "userName",
      minWidth: 90
    },
    {
      title: this.$t("module.userManage.cellPhoneNumber"), // 手机号码
      key: "mobile",
      minWidth: 110
    },
    {
      title: this.$t("module.userManage.email"), // 电子邮件
      key: "email",
      minWidth: 90
    },
    {
      title: this.$t("common.status"),
      align: "left",
      key: "locked",
      width: 100,
      render: (h, params) => {
        return h(
          "StatusButton",
          {
            props: {
              status: params.row.locked == "0" ? "0" : "1"
            }
          },
          params.row.locked == "0" ? this.$t("common.valid") : this.$t("common.invalid")
        );
      }
    }
  ];
}
export function tenantStatisticsColumns() {
  const COLUMN_WIDTH = window.RPConfig.COLUMN_WIDTH
  return [
    {
      title: this.$t("module.tenantManage.tenantCode"), // 租户编码
      key: "tenantCode",
      sortable: "custom"
    },
    {
      title: this.$t("module.tenantManage.tenantName"), // 租户名称
      key: "tenantName",
      sortable: "custom"
    },
    {
      title: this.$t("module.appManage.appCode"),
      key: "applicationId",
    },
    {
      title: this.$t("module.appManage.appName"),
      key: "appName",
    },
    {
      title: this.$t("module.tenantManage.statistics.userNum"),
      key: "userNum",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.tenantManage.statistics.functionNum"),
      key: "functionNum",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.tenantManage.statistics.resourceNum"),
      key: "resourceNum",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_4_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.tenantManage.statistics.nacosNum"),
      key: "nacosNum",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_5_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_5_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE
    },
    {
      title: this.$t("module.tenantManage.statistics.gwNum"),
      key: "gwNum",
      minWidth: COLUMN_WIDTH.COLUMN_WIDTH_5_WORDS,
      maxWidth: COLUMN_WIDTH.COLUMN_WIDTH_5_WORDS + COLUMN_WIDTH.MAX_WIDTH_MORE
    }
  ];
}
